var http = require("http");
var qs = require("querystring");
var url = require("url");
var util = require("util");

function start(route) {
    function onRequest(request, response) {
	var postData = null;   
	if (request.method == 'POST') {
            var rawData = '';
	    request.setEncoding("utf8");
            request.on('data', function (data) {
		rawData += data;
            });
            request.on('end', function () {
		postData = qs.parse(rawData);
		route(request, response, postData);
            });
	} else {
	    route(request, response, postData);
	}
    }

    http.createServer(onRequest).listen(8888);
}

exports.start = start;

